import 'package:flutter/material.dart';
import 'package:flutter_rider/main/widgets/ext/u_text.dart';
import 'package:flutter_rider/main/widgets/ui_constant.dart';
import 'package:flutter_rider/utils/screen_fit.dart';
import '../../../utils/func_callback.dart';

class PopPickSpu extends StatefulWidget {
  List list;
  String nameKey;
  IntCallback callback;
  int initItem;
  PopPickSpu({required this.list, required this.nameKey, required this.callback, this.initItem = 0});

  @override
  State<StatefulWidget> createState() {
    return PopPickSpuState();
  }
}

class PopPickSpuState extends State<PopPickSpu> {
  int _index = 0;
  late FixedExtentScrollController _controller;

  @override
  void initState() {
    super.initState();
    _controller = FixedExtentScrollController(initialItem: widget.initItem);
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 300.rpx,
      width: double.infinity,
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.vertical(top: Radius.circular(8.rpx)),
      ),
      child: Column(
        children: [
          SizedBox(
            height: 64.rpx,
            child: Row(
              children: [
                TextButton(onPressed: () {
                  Navigator.of(context).pop();
                }, child: UText.get("取消", UIColor.color_t3, 14.rpx),),
                Expanded(child: Center(child: UText.getMainText("选择货物类别"))),
                TextButton(onPressed: () {
                  widget.callback(_index);
                  Navigator.of(context).pop();
                }, child: UText.get("确定", UIColor.color_primary, 14.rpx),),
              ],
            ),
          ),
          Expanded(
            child: ListWheelScrollView.useDelegate(
              controller: _controller,
              itemExtent: 48,
              childDelegate: ListWheelChildBuilderDelegate(
                builder: (context, index) {
                  return Container(
                    padding: EdgeInsets.symmetric(horizontal: 12.rpx),
                    margin: EdgeInsets.symmetric(vertical: 10.rpx, horizontal: 30.rpx),
                    child: UText.getMainText(widget.list[index][widget.nameKey]),
                  );
                },
                childCount: widget.list.length,
              ),
              useMagnifier: true,
              magnification: 1.3,
              overAndUnderCenterOpacity: 0.85,
              onSelectedItemChanged: (index) {
                _index = index;
              },
            ),
          ),
        ],
      ),
    );
  }
}
